package com.yunqing.restkeeper.enterprise.web.controller.shop;

import com.yunqing.restkeeper.enterprise.web.vo.shop.StoreManagerVO;
import com.yunqing.restkeeper.shop.api.entity.StoreManager;
import com.yunqing.restkeeper.shop.api.service.IStoreManagerService;
import com.yunqing.restkeeper.web.common.response.vo.PageVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName StoreManagerController
 * @Description TODO
 * @author: puyunqing
 * @Date: 2025/7/4
 */
@RestController
@RequestMapping("/storeManger")
@Tag(name = "门店管理员接口")
public class StoreManagerController {

    @DubboReference(version = "1.0.0", check = false)
    private IStoreManagerService storeManagerService;

    /**
     * 查询分页数据
     */
    @Operation(summary = "查询分页数据")
    @Parameters({
            @Parameter(in = ParameterIn.PATH, name = "page", description = "当前页码", required = false, schema = @Schema(type = "Integer")),
            @Parameter(in = ParameterIn.PATH, name = "pageSize", description = "分大小", required = false, schema = @Schema(type = "Integer")),
            @Parameter(in = ParameterIn.QUERY, name = "criteria", description = "查询条件", required = false, schema = @Schema(type = "String"))})
    @PostMapping(value = "/pageList/{page}/{pageSize}")
    public PageVO<StoreManager> findListByPage(@PathVariable int page,
                                               @PathVariable int pageSize,
                                               @RequestParam(value = "criteria", required = false) String criteria) {
        return new PageVO<>(storeManagerService.queryPageByCriteria(page, pageSize, criteria));
    }

    /**
     * 添加店长
     */
    @Operation(summary = "添加店长")
    @PostMapping(value = "/add")
    public boolean add(@RequestBody StoreManagerVO storeManagerVO) {
        return storeManagerService.addStoreManager(
                storeManagerVO.getName(),
                storeManagerVO.getPhone(),
                storeManagerVO.getStoreIds());
    }

    /**
     * 门店管理员修改接口
     */
    @Operation(summary = "更新数据")
    @PutMapping(value = "/update")
    public boolean update(@RequestBody StoreManagerVO storeManagerVO) {
        return storeManagerService.updateStoreManager(storeManagerVO.getStoreManagerId(),
                storeManagerVO.getName(),
                storeManagerVO.getPhone(),
                storeManagerVO.getStoreIds());
    }

    /**
     * 删除门店管理员
     */
    @Operation(summary = "删除数据")
    @DeleteMapping(value = "/del/{id}")
    public boolean delete(@PathVariable String id) {
        return storeManagerService.deleteStoreManager(id);
    }

    /**
     * 停用
     */
    @Operation(summary = "门店管理员停用")
    @PutMapping(value = "/pause/{id}")
    public boolean pause(@PathVariable String id) {
        return storeManagerService.pauseStoreManager(id);
    }
}
